﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Edit.ascx.vb" Inherits="Control_MSDS_Edit" %>

<script type="text/javascript">
    function ajaxJquery() {
        // focus textbox first
        $(".TextBox:first").focus();
        //Upload Image
        $('#file_upload').uploadify({
            'uploader': '<%=ResolveUrl("~/uploadify/uploadify.swf")%>',
            'script': '<%=ResolveUrl("~/uploadify/Upload.ashx?folder=ImageStorage")%>',
            'cancelImg': '<%=ResolveUrl("~/uploadify/cancel.png")%>',
            'folder': '<%=ResolveUrl("~/Uploads")%>',
            'auto': false,
            'multi': false,
            'fileExt': '*.doc;*.docx;*.pdf;*.xls;*.xlsx',
            'fileDesc': 'Files (.DOC, .DOCX, .PDF)',
            'fileDataName': 'myfile',
            'sizeLimit': '<%= ConfigurationManager.AppSettings("maxupload") %>',
            'onComplete': function (event, ID, fileObj, response, data) {
                $('#<%=hidImagePath.ClientID %>').val('<%= ConfigurationManager.AppSettings("ImageDomain") %>' + response);
                $('#<%=hplFile.ClientID %>').text('<%= ConfigurationManager.AppSettings("ImageDomain") %>' + response);
                $('#<%=hplFile.ClientID %>').attr('href', '<%= ConfigurationManager.AppSettings("ImageDomain") %>' + response);
            }
        });

        $('#file_upload2').uploadify({
            'uploader': '<%=ResolveUrl("~/uploadify/uploadify.swf")%>',
            'script': '<%=ResolveUrl("~/uploadify/Upload.ashx?folder=ImageStorage")%>',
            'cancelImg': '<%=ResolveUrl("~/uploadify/cancel.png")%>',
            'folder': '<%=ResolveUrl("~/Uploads")%>',
            'auto': false,
            'multi': false,
            'fileExt': '*.doc;*.docx;*.pdf;*.xls;*.xlsx',
            'fileDesc': 'Files (.DOC, .DOCX, .PDF)',
            'fileDataName': 'myfile',
            'sizeLimit': '<%= ConfigurationManager.AppSettings("maxupload") %>',
            'onComplete': function (event, ID, fileObj, response, data) {
                $('#<%=hidImagePath2.ClientID %>').val('<%= ConfigurationManager.AppSettings("ImageDomain") %>' + response);
                $('#<%=hplFile2.ClientID %>').text('<%= ConfigurationManager.AppSettings("ImageDomain") %>' + response);
                $('#<%=hplFile2.ClientID %>').attr('href', '<%= ConfigurationManager.AppSettings("ImageDomain") %>' + response);
            }
        });


        // Init Autocomplete for textBox ItemCode
        /// Set AutoComplete for UNII
        $("#txtItemcode").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: '<%=ResolveUrl("~/Services/wsAutoComplete.asmx/GetAutoCompleteVendor")%>',
                    data: "{ 'strSrc': '" + request.term.trim() + "'}",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    beforeSend: function () {
                    },
                    dataFilter: function (data) {
                        return data;
                    },
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                label: item.FullText, value: item.ID
                            }
                        }))
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        //Alertbox(textStatus);
                    },
                    complete: function () {
                    }
                });
            },
            focus: function (event, ui) {
                $(this).val(ui.item.value);
                return false;
            },
            select: function (event, ui) {
                var _itemCode = ui.item.value;
                $(this).val(_itemCode);
                $("#hidItemCode").val(_itemCode);
                $("#txtItemname").val(ui.item.label);
                setTimeout(FilterVendorCode(_itemCode), 1000);
                return false;
            },
            minLength: 1
        });
        

        // Check divVendorCode has html ==> show again
        if ($("#drpVendorCode").data("html") != undefined && $("#drpVendorCode").data("html") != "undefined") {
            var _htmlRender = $("#drpVendorCode").data("html");
            $("#drpVendorCode").html(_htmlRender);
        }
        else {
            // Create DropDowList 
            FilterVendorCode($("#hidItemCode").val());
            // select item by value 
            setTimeout(function () { $("#drpVendorCode option:contains(" + $("#<%=hidVendorCode.ClientID() %>").val() + ")").attr('selected', 'selected') }, 1000);
        }

    } //********************** END INNIT FUNCTION ***************************


    // function Ajax filter Vendor Code by ItemCode
    function FilterVendorCode(_itemCode) {
        $.ajax({
            url: '<%=ResolveUrl("~/Services/wsAutoComplete.asmx/GetListVendor")%>',
            data: "{ 'itemCode': '" + _itemCode + "'}",
            dataType: "json",
            type: "POST",
            contentType: "application/json; charset=utf-8",
            beforeSend: function () {

            },
            dataFilter: function (data) {
                return data;
            },
            success: function (data) {
                if (data.d != null) {
                    var _html = "<option value=''> --- Chọn --- </option>";
                    $.each(data.d, function (idx, obj) {
                        _html += ("<option value='" + obj.ID + "'>" + obj.ID + " - " + obj.FullText + "</option>");
                    });
                    //var _htmlRender = $("<select class='DropDownList' onchange = 'SetVendorCode(this);'>").append(_html);
                    //$("#divVendorCode").data("html", _htmlRender)
                    //$("#divVendorCode").html(_htmlRender);
                    $("#drpVendorCode").data("html", _html)
                    $("#drpVendorCode").html(_html);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                //Alertbox(textStatus);
            },
            complete: function () {
            }
        });
        return true;
    }

    // Function set Vendor Code and vendorName
    function SetVendorCode(obj) {
        var _value = obj.options[obj.selectedIndex].value;
        var _text = obj.options[obj.selectedIndex].text.replace(_value + " - ", "");

        $("#<%=hidVendorCode.ClientID() %>").val(_value);
        $("#txtVendorname").val(_text.replace("--- Chọn ---", ''));
        
    }
   
</script>


<div class="BoxField">

	<div class="HeadTitle">
		<h3>CHỈNH SỬA MSDS</h3>
	</div>
   <div class="DivRequired">
       <span class="fieldRequired">&nbsp;</span>Trường yêu cầu nhập dữ liệu
   </div>
   <div class="Error">
      <asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="#FF3300" />
  </div>
	<div class="DivRow">
		<div class="DivLabel">
			<asp:Label ID="lblItemcode" CssClass="TextLabel" runat="server" Text="Item Code:" />
			<span class="fieldRequired">&nbsp;</span>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtItemcode"
                Display="None" ErrorMessage="Vui lòng nhập itemcode" SetFocusOnError="True" />
		</div>
		<div class="DivTextBox">
			<asp:TextBox ID="txtItemcode" CssClass="TextBox" runat="server" Text="" ClientIDMode="Static" />
			<asp:HiddenField runat="server" ID="hidItemCode" Value="" ClientIDMode="Static" />
		</div>
	</div>
	<div class="DivRow">
		<div class="DivLabel">
			<asp:Label ID="lblItemname" CssClass="TextLabel" runat="server" Text="Item Name:" />
		</div>
		<div class="DivTextBox">
			<asp:TextBox ID="txtItemname" CssClass="TextBox" runat="server" Text="" ClientIDMode="Static" />
		</div>
	</div>
	<div class="DivRow" style="height: 30px">
		<div class="DivLabel">
			<asp:Label ID="lblVendorcode" CssClass="TextLabel" runat="server" Text="Vendor Code:" /><span class="fieldRequired">&nbsp;</span>
			
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="hidVendorCode"
                Display="None" ErrorMessage="Vui lòng chọn vendor" SetFocusOnError="True" />
		</div>
		<div class="DivTextBox" id="divVendorCode">
			<select id="drpVendorCode" class='DropDownList' onchange='SetVendorCode(this);'>
				<option value="0">--- Chọn ---</option>
			</select>
		</div>
		

	</div>
	<div class="DivRow">
		<div class="DivLabel">
			<asp:Label ID="lblVendorname" CssClass="TextLabel" runat="server" Text="Vendor Name:" />
		</div>
		<div class="DivTextBox">
			<asp:TextBox ID="txtVendorname" CssClass="TextBox" runat="server" Text="" ClientIDMode="Static" />
		</div>
	</div>
	<div class="DivRow">
		<div class="DivLabel">
			<asp:Label ID="lblOrigin" CssClass="TextLabel" runat="server" Text="Origin:" />
		</div>
		<div class="DivTextBox">
			<asp:TextBox ID="txtOriginal" CssClass="TextBox" runat="server" Text="" ClientIDMode="Static" />
		</div>
	</div>
	<div class="DivRow">
		<div class="DivLabel">
			<asp:Label ID="Label2" CssClass="TextLabel" runat="server" Text="URL:" />
		</div>
		<div class="DivTextBox">
			<asp:TextBox ID="txtURL" CssClass="TextBox" runat="server" Text="" />
		    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                ErrorMessage="Vui lòng nhập đúng định dạng URL"  Display="None" 
                ControlToValidate="txtURL" 
                ValidationExpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&amp;=]*)?"  ></asp:RegularExpressionValidator>
		</div>


	</div>
   <div class="DivRow">
        <div class="DivLabel">
            <asp:Label ID="Label1" CssClass="TextLabel" runat="server" Text="Original MSDS:" />
                    
            
        </div>
        <div class="DivTextBox">
            <input id="file_upload" name="file_upload" type="file" />
                <a id="upload" href="javascript:$('#file_upload').uploadifyUpload();">Upload Files</a>
        </div>
    </div>
    <div class="DivRow">
        <div class="DivLabel">&nbsp;
        </div>
        <div class="DivTextBox"><asp:HyperLink ID="hplFile" runat="server" Text="" Target="_blank"></asp:HyperLink>
        </div>
    </div>

    <div class="DivRow">
        <div class="DivLabel">
            <asp:Label ID="Label3" CssClass="TextLabel" runat="server" Text="Translated MSDS:" />
        </div>
        <div class="DivTextBox">
            <input id="file_upload2" name="file_upload2" type="file" />
                <a id="upload2" href="javascript:$('#file_upload2').uploadifyUpload();">Upload Files</a>
        </div>
    </div>


    <div class="DivRow">
        <div class="DivLabel">&nbsp;
        </div>
        <div class="DivTextBox"><asp:HyperLink ID="hplFile2" runat="server" Text="" Target="_blank"></asp:HyperLink>
        </div>
    </div>
<div class="DivRow">
		<div class="DivLabel">
			<asp:Label ID="Label4" CssClass="TextLabel" runat="server" Text="PPE:" />
		</div>
		<div class="DivTextBox">
			<asp:TextBox ID="txtPPE" CssClass="TextArea" runat="server" Text="" TextMode="MultiLine" />
		
		</div>


	</div>

	<div class="DivRow" style="margin-top:10px">
		<div class="DivLabel">
			&nbsp;&nbsp;&nbsp;
		</div>
		<div class="DivTextBox">
			<div style="float: left">
				<asp:Button ID="btnSave" runat="server" Text=" Lưu " CssClass="btn"  />
				&nbsp;<asp:Button ID="btnReset" runat="server" CausesValidation="false" CssClass="btn"
					Text="Làm lại" />
			</div>
			<div style="float: right; text-align: right; display:none">
				&nbsp;<asp:ImageButton ID="btnBack" ImageAlign="AbsMiddle" ToolTip="Quay lại" runat="server"
					ImageUrl="~/images/back.png" />
			</div>
		</div>
	</div>
</div>
<div style="display: none">
	<asp:HiddenField ID="hidID" Value="0" runat="server" />
    <asp:TextBox ID="hidImagePath" Text="" runat="server"  />
    <asp:TextBox ID="hidImagePath2" Text="" runat="server"  />
    <asp:TextBox ID="hidVendorCode" runat="server" Text="" />
</div>

